package com.wqj.kyee.mmitest

import android.R
import android.support.v4.content.ContextCompat
import android.view.View
import android.widget.AdapterView
import android.widget.ArrayAdapter
import org.jetbrains.anko.*

/**
 * Created by kyee on 17-12-5.
 */
class MainUi: AnkoComponent<MainActivity> {
    val items = arrayOf("NFC","WLAN","LCD屏","触摸屏","音频","摄像头","按钮")

    override fun createView(ui: AnkoContext<MainActivity>): View {
        return with(ui) {
            verticalLayout {
                padding = dip(16)
                backgroundColor = ContextCompat.getColor(ui.ctx, android.R.color.white)
                val list = listView() {
                    adapter = ArrayAdapter<String>(ctx, R.layout.simple_list_item_1, items)
                    onItemClickListener = object : AdapterView.OnItemClickListener {
                        override fun onItemClick(parent: AdapterView<*>?, v: View?, position: Int, id: Long) {
                            when (position) {
                                0 -> {
                                    startActivity<NfcActivity>()
                                }
                            }
                        }
                    }
                }.lparams(width = matchParent) {
                    height = matchParent
                }
            }
        }
    }
}